package com.example.operation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.operation.domin.DecWaresClassify;
import com.example.operation.dto.DecWaresClassifyDto;
import com.example.operation.service.impl.DecWaresClassifyServiceImpl;
import com.example.operation.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Api(tags = "分类管理")
@RestController
@RequestMapping("/decWaresClassify")
public class DecWaresClassifyController {

    @Autowired
    private DecWaresClassifyServiceImpl decWaresClassifyService;

    @ApiOperation(value = "新增商品分类接口")
    @PostMapping("/save")
    public Result<String> save(@RequestBody DecWaresClassifyDto decWaresClassifyDto){
        decWaresClassifyService.insert(decWaresClassifyDto);
        return Result.ok("商品分类新增成功");
    }

    @ApiOperation(value = "修改商品分类接口")
    @PutMapping("/update")
    public Integer update(@RequestBody DecWaresClassifyDto decWaresClassifyDto){
        return decWaresClassifyService.update(decWaresClassifyDto);
    }

    @ApiOperation(value = "商品分类分页模糊查询接口")
    @GetMapping("/page")
    public Result<Page<DecWaresClassify>> pageResult(
            @RequestParam(value = "pageCurrent") @ApiParam(value = "当前页码",required = true) @NotNull(message = "当前页码不为空") Integer pageCurrent,
            @RequestParam(value = "pageSize") @ApiParam(value = "分页条数",required = true) @NotNull(message = "分页条数不能为空") Integer pageSize,
            @RequestParam(value = "pageNumber") @ApiParam(value = "分页页码",required = true) @NotNull(message = "分页页码") Integer pageNumber,
            @RequestParam(value = "name",required = false) @ApiParam(value = "分类名称") String name){
        Page<DecWaresClassify> page = decWaresClassifyService.page(pageCurrent,pageSize, pageNumber, name);
        return Result.ok(page);
    }

    @ApiOperation(value = "商品分类删除接口")
    @DeleteMapping("/delectById")
    public Integer delectById(@RequestParam(value = "id") Integer id){
        return decWaresClassifyService.delectById(id);
    }

    @ApiOperation(value = "商品分类查询接口")
    @GetMapping("/selectById")
    public DecWaresClassify selectById(@RequestParam(value = "id") Integer id){
        return decWaresClassifyService.selectById(id);
    }
}
